﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.UI.WebControls;

using CharityGamesOnline.Modules.Common;

namespace CharityGamesOnline.Modules.Account
{
    public partial class AccountManagement : CGOBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                BindData();
            }

            catch (Exception exc)
            {
                //Module failed to load 
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            foreach (DataGridColumn column in grdAccount.Columns)
            {
                if (object.ReferenceEquals(column.GetType(), typeof(ImageCommandColumn)))
                {
                    ImageCommandColumn imageColumn = (ImageCommandColumn)column;
                    if (!String.IsNullOrEmpty(imageColumn.CommandName))
                    {
                        imageColumn.Text = Localization.GetString(imageColumn.CommandName, this.LocalResourceFile);
                    }
                    if (imageColumn.CommandName == "Edit")
                    {
                        string formatString = ModuleContext.EditUrl("UserID", "KEYFIELD", "Edit");
                        formatString = formatString.Replace("KEYFIELD", "{0}");
                        imageColumn.NavigateURLFormatString = formatString;
                    }
                }
            }
        }

        private void BindData()
        {
            AccountController ctrlAccount = new AccountController();
            List<AccountInfo> lstAccount;

            lstAccount = ctrlAccount.GetAccounts(PortalId);

            grdAccount.DataSource = lstAccount;
            grdAccount.DataBind();
        }
    }
}